home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT11.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.0 KB  |  109 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 11                         
  5.                                                                               
  6.  Shows the use of wgetblockwidth and wgetblockheight, and demonstrates        
  7.  the wresize procedure.                                                        
  8.                                                                               
  9.  *** PROJECT ***                                                             
  10.  This program requires the file WGT5_WC.LIB to be linked.                    
  11.                                                                               
  12.  *** DATA FILES ***                                                          
  13.  WGT1.PCX                                                          
  14.                                                            WATCOM C++ VERSION 
  15. ==============================================================================
  16. */
  17.  
  18. #include <wgt5.h>
  19.  
  20.  
  21. #define TIMERSPEED 60
  22. int timer;
  23. int size;
  24. int direction = -1;
  25.  
  26. void timer_routine (void)
  27. {
  28.  timer++;
  29. }
  30.  
  31.  
  32. void main(void)
  33. {
  34.   short i,x,y;
  35.   short oldmode;
  36.   block part1;                    /* part of the screen */
  37.   color pal[256];
  38.  
  39.   printf ("WGT Example #11\n\n");
  40.   printf ("This program will load a bitmap from a file and display it on the screen.\n");
  41.   printf ("It will then switch back to text mode and display how big the picture is.\n");
  42.   printf ("Graphics mode is entered and the image is resized until a key is\n");
  43.   printf ("pressed.\n");
  44.   printf ("\n\nPress any key to continue.\n");
  45.   getch ();
  46.  
  47.   if ( !vgadetected () )
  48.   {
  49.     printf("Error - VGA card required for any WGT program.\n");
  50.     exit (0);
  51.   }
  52.   oldmode = wgetmode ();
  53.   vga256 ();
  54.  
  55.   part1 = wloadpcx ("wgt1.pcx", pal);
  56.   wsetpalette (0, 255, pal);
  57.  
  58.   wnormscreen ();
  59.   wputblock (0, 0, part1, 0);
  60.  
  61.  
  62.   getch ();
  63.   wcls (0);
  64.   x = wgetblockwidth (part1);
  65.   y = wgetblockheight (part1);
  66.  
  67.   wsetmode (oldmode);               
  68.   printf ("Block width : %i\n",x);  
  69.   printf ("Block height: %i\n",y);
  70.   printf ("Block size is %u bytes.",x*y+4);  /* Add 4 bytes for width and height */
  71.   printf ("\nPress any key to resize...\n");
  72.   getch ();
  73.   vga256 ();
  74.   wsetpalette (0, 255, pal);
  75.  
  76.   timer = 0;
  77.   size = 50;
  78.   winittimer ();
  79.   wstarttimer (timer_routine, TICKS(TIMERSPEED));
  80.  
  81.   wclip (0, 0, 319, 199);
  82.   do {
  83.     if (direction > 0)
  84.       {
  85.        size += timer * 2;
  86.        timer = 0;
  87.        if (size > 50)
  88.          direction = -1;
  89.       }   
  90.     else 
  91.       {
  92.        size -= timer * 2;
  93.        timer = 0;
  94.        if (size < -1000)
  95.          direction = 1;
  96.       }   
  97.  
  98.     wresize (size, size, 319 - size, 199 - size, part1, NORMAL);
  99.   
  100.   } while (!kbhit ());
  101.   getch ();
  102.  
  103.   wstoptimer (); 
  104.   wdonetimer ();
  105.  
  106.   wfreeblock (part1);
  107.   wsetmode (oldmode);
  108. }
  109.